package presentation;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.hibernate.Session;

import db.*;

 public class EnterInAlbumServlet extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {

	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		int pageNumber=0;
		try{
			 pageNumber=Integer.parseInt(request.getParameter("page"));
		}catch(Exception e){
			 pageNumber=1;
		}
		String albumIdStr = request.getParameter("album_id");
		if(albumIdStr == null) {
			response.sendRedirect("Error.jsp");
			return;
		}
		long albumId = Long.parseLong(albumIdStr);
		Session hbSession = DbUtils.startSession();
		//Album album = DbUtils.findAlbum(hbSession, albumId);
		//List<Album> childAlbums = album.getChildAlbums();
		List<Album> childAlbums= DbUtils.get16ChildAlbumsByParent(hbSession, albumId, pageNumber);
		HttpSession session = request.getSession();
		session.setAttribute("current_album_id", albumId);
		session.setAttribute("user_albums", childAlbums);
		//try{
		//	session.setAttribute("parent_album_id", album.getParentAlbum().getAlbumId());
		//}catch (Exception e) {
		//}
		response.sendRedirect("Home.jsp?album_id="+albumId);
	}  	  	  	    
}